const app = getApp();
Page({
  data: {
    isFullScreen: true,
    isDev: false,
    userInfo: {
      avatarUrl: '',
      nickName: '',
      gender: 0,
      city: '',
      province: '',
      country: '',
      language: '',
    },
    tutorialModalVisiable: false,
  },
  async onLoad(options) {
    const userInfo = tt.getStorageSync('userInfo');
    if (userInfo) {
      this.setData({ userInfo, isDev: app.globalData.isDev })
    }
  },
  onHide() {
    this.setData({ tutorialModalVisiable: false })
  },
  onShow() {
    this.refreshScreenRatio();
  },
  onResize(res) {
    this.setData({ isFullScreen: res.screenRatio === 1 })
  },
  onReady() {
    this.refreshScreenRatio();
  },
  refreshScreenRatio() {
    this.setData({ isFullScreen: app.utils.isFullScreen() })
  },
  // 获取头像与昵称
  getUserProfile() {
    tt.getUserProfile({
      success: ({ userInfo }) => {
        tt.setStorageSync('userInfo', userInfo);
        this.setData({
          userInfo: Object.assign({}, userInfo)
        })
      }
    })
  },
  purchaseHistory() {
    tt.navigateTo({ url: '/pages/purchaseHistory/purchaseHistory' });
  },
  codeHistory() {
    tt.navigateTo({ url: '/pages/codeHistory/codeHistory' });
  },
  clearStroage() {
    tt.clearStorageSync();
    tt.showToast({ title: '好了' });
  },
  switchTutorial() {
    this.setData({ tutorialModalVisiable: !this.data.tutorialModalVisiable })
  }
})